package com.wt.test.ai.springai.manager;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.image.ImageModel;
import org.springframework.ai.image.ImageOptions;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * @author qiyu
 * @since 2025/2/6
 */
@Component
@Slf4j
public class ImageManager {
    
    @Resource
    @Qualifier("stabilityAiImageModel")
    private  ImageModel imageModel;
    
    @Resource
    private  ImageOptions imageOptions;
    
    public String generateImage(String imageContent) {
        // 调用OpenAI聊天模型的call方法，传入message参数，得到返回结果
        ImageResponse imageResponse = imageModel.call(new ImagePrompt(imageContent, imageOptions));
        String result = imageResponse.getResult().getOutput().getUrl();
        // 返回结果
        return result;
    }
}
